/**
 * 手写useEffect
 *      useEffect 的基本实现
 * */

let depArr = [];

function useEffect(callback, deps) {
  //    判断deps是否有改变
  let isChange, isMount;
  if (typeof callback !== "function")
    throw TypeError("callback must a function!");
  if (isMount) {
    depArr = deps;
    callback && callback();
  } else {
    isChange = depArr.some((item, index) => item !== deps[index]);
  }

  if (isMount || isChange) {
    callback && callback();
  }
}
